package com.example.finaltask;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.example.finaltask.utils.DBHelper;
import com.example.finaltask.utils.Remove;

public class MainActivity extends AppCompatActivity {
    private SQLiteDatabase db;
    private Context mContext;
    private com.example.finaltask.utils.DBHelper DBHelper;
    final int TIME=10;//定义时间长度
    final int MSG_CODE=0x001;//定义消息代码
    private ProgressBar progressBar;//声明水平进度条
    private int mProgressStatus=0;//定义完成进度


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressBar=findViewById(R.id.timer);//获取进度条组件
        handler.sendEmptyMessage(MSG_CODE);//发送消息，启动进度条

        mContext=MainActivity.this;
        DBHelper dbsqLiteOpenHelper = new DBHelper(MainActivity.this,"murmur.db",null,7);
        SQLiteDatabase db = dbsqLiteOpenHelper.getWritableDatabase();
        Remove.removeTop(this);

        //初始化收集链接按钮并注册监听器
        Button LoginBnt = findViewById(R.id.LoginBnt);
        LoginBnt.setOnClickListener(onClickListener);

    }
    //创建Handle控制进度条
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // 当前进度大于0
            if (TIME - mProgressStatus > 0) {
                mProgressStatus++;
                // 进度+1
                progressBar.setProgress(mProgressStatus);
                // 更新进度条的显示进度
                handler.sendEmptyMessageDelayed(MSG_CODE, 1000);
                // 延迟一秒发送消息
            } else {//提示时间已到
                Toast.makeText(MainActivity.this, "加载完毕", Toast.LENGTH_SHORT).show();
            }
        }
    };

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                    //db = DBHelper.getWritableDatabase();
                    switch (v.getId()) {
                        case R.id.LoginBnt://返回
                            Intent intent=new Intent();
                            intent.setClass(MainActivity.this,LoginActivity.class);
                             startActivity(intent);
                            break;
                    }
                }

        };
    }